﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using EdiNet;
using System.Resources;
using System.Reflection;
using System.Diagnostics;

namespace EdiNet.Test
{
    static class StreamHelper
    {
        static Assembly asm;
        static StreamHelper()
        {
            asm = typeof(StreamHelper).Assembly;
        }

        public static MemoryStream CreateStreamFromString(string str)
        {
            return new MemoryStream(DefaultEdiEncoding.Encoding.GetBytes(str));
        }
        public static byte[] CreateArrayFromString(string str)
        {
            return DefaultEdiEncoding.Encoding.GetBytes(str);
        }
        public static string StringFromAray(byte[] buffer)
        {
            return DefaultEdiEncoding.Encoding.GetString(buffer);
        }

        public static Stream GetResourceStream(string basePath, string name)
        {
            Stream res = asm.GetManifestResourceStream("EdiNet.Test.TestData." + basePath + "." + name);
            if (null == res)
                Debugger.Break();
            return res;

        }
        public static Stream CreateTempFileStream()
        {
            return File.Create(Path.GetTempFileName());
        }

    }
}
